package com.lc.user.express.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lc.user.express.R;
import com.lc.user.express.app.AppContext;



/**
 * @ClassName: PayPasswordView 
 * @Function: TODO 密码数字键盘
 * @date: 2015-10-29 下午5:44:37
 * @author Administrator
 * @version 
 * @since    JDK 1.6
 */
@SuppressLint("InflateParams")
public class PayPasswordView implements View.OnClickListener {

    private ImageView del;

    private ImageView zero;

    private ImageView one;

    private ImageView two;

    private ImageView three;

    private ImageView four;

    private ImageView five;

    private ImageView six;

    private ImageView seven;

    private ImageView eight;

    private ImageView nine;

    private View mView;

    private OnPayListener listener;

    public PayPasswordView(Context mContext, OnPayListener listener) {
        getDecorView(mContext, listener);
    }

    public static PayPasswordView getInstance(Context mContext, OnPayListener listener) {
        return new PayPasswordView(mContext, listener);
    }

    public void getDecorView(Context mContext, OnPayListener listener) {
        this.listener = listener;
        mView = LayoutInflater.from(mContext).inflate(R.layout.item_paypassword, null);
        AppContext.ScaleScreenHelper.loadView((ViewGroup) mView);
        initView(mView);
    }

    private void initView(View mView) {

        // TODO Auto-generated method stub
        del = (ImageView) mView.findViewById(R.id.pay_keyboard_del);
        zero = (ImageView) mView.findViewById(R.id.pay_keyboard_zero);
        nine = (ImageView) mView.findViewById(R.id.pay_keyboard_nine);
        eight = (ImageView) mView.findViewById(R.id.pay_keyboard_eight);
        seven = (ImageView) mView.findViewById(R.id.pay_keyboard_seven);
        six = (ImageView) mView.findViewById(R.id.pay_keyboard_six);
        five = (ImageView) mView.findViewById(R.id.pay_keyboard_five);
        four = (ImageView) mView.findViewById(R.id.pay_keyboard_four);
        three = (ImageView) mView.findViewById(R.id.pay_keyboard_three);
        two = (ImageView) mView.findViewById(R.id.pay_keyboard_two);
        one = (ImageView) mView.findViewById(R.id.pay_keyboard_one);
        one.setOnClickListener(this);
        two.setOnClickListener(this);
        three.setOnClickListener(this);
        four.setOnClickListener(this);
        five.setOnClickListener(this);
        six.setOnClickListener(this);
        seven.setOnClickListener(this);
        eight.setOnClickListener(this);
        nine.setOnClickListener(this);
        zero.setOnClickListener(this);
        del.setOnClickListener(this);

    }

    private void parseActionType(KeyboardEnum type) {
        // TODO Auto-generated method stub
        if (type.getType() == KeyboardEnum.ActionEnum.add) {
            listener.onInput(type.getValue());
        } else if (type.getType() == KeyboardEnum.ActionEnum.delete) {
            listener.onDelete();
        }

    }

    public View getView() {
        return mView;
    }

    @Override
    public void onClick(View v) {

        // TODO Auto-generated method stub
        if (v == zero) {
            parseActionType(KeyboardEnum.zero);
        } else if (v == one) {
            parseActionType(KeyboardEnum.one);
        } else if (v == two) {
            parseActionType(KeyboardEnum.two);
        } else if (v == three) {
            parseActionType(KeyboardEnum.three);
        } else if (v == four) {
            parseActionType(KeyboardEnum.four);
        } else if (v == five) {
            parseActionType(KeyboardEnum.five);
        } else if (v == six) {
            parseActionType(KeyboardEnum.sex);
        } else if (v == seven) {
            parseActionType(KeyboardEnum.seven);
        } else if (v == eight) {
            parseActionType(KeyboardEnum.eight);
        } else if (v == nine) {
            parseActionType(KeyboardEnum.nine);
        } else if (v == del) {
            parseActionType(KeyboardEnum.del);
        }
    }

    /**
     * @ClassName: OnPayListener 
     * @Function: TODO 监听输入数字键盘
     * @date: 2015-10-29 下午5:43:53
     * @author Administrator
     * @version PayPasswordView
     * @since    JDK 1.6
     */
    public interface OnPayListener {

        void onDelete();// 删除

        void onInput(String password);// 输入
    }

}
